package com.sgb.kjwl.viewmodel.packers;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;

import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.api.NewAPIManager;
import com.sgb.kjwl.model.entity.packers.ApplyCompanyEntity;
import com.sgb.kjwl.model.entity.packers.MyCompanyEntity;
import com.sgb.kjwl.model.entity.user.UnitEntity;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.common.base.BaseViewModel;
import com.swgk.core.view.selection.CommonPopEntity;

import org.jetbrains.annotations.NotNull;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * @author: 王彬臣
 * @date: 2021/9/6
 * @Description: 工队申请加盟viewModel
 */
public class TeamApplyJoinModel extends BaseViewModel {
    public MutableLiveData<List<CommonPopEntity>> ldLevel=new MutableLiveData<>();
    public MutableLiveData<List<CommonPopEntity>> ldType=new MutableLiveData<>();
    public MutableLiveData<List<MyCompanyEntity>> ldCompany=new MutableLiveData<>();
    public MutableLiveData<Boolean> ldResult=new MutableLiveData<>();

    public TeamApplyJoinModel(@NonNull @NotNull Application application) {
        super(application);
    }

   //会员等级
    public void getMemberLevels(){
        NewAPIManager.getInstance().getTeamNewInterfaceAPI().getMemberLeve().enqueue(new ICallBack<BaseEntity<List<CommonPopEntity>>>() {
            @Override
            public void onSuccess(BaseEntity<List<CommonPopEntity>> data) {
                if(data.isSuccess()) {
                    ldLevel.postValue(data.getData());
                }
            }
        });
    }
    //会员类型
    public void getMemberType(){
        NewAPIManager.getInstance().getTeamNewInterfaceAPI().getMemberTypeList().enqueue(new ICallBack<BaseEntity<List<CommonPopEntity>>>() {
            @Override
            public void onSuccess(BaseEntity<List<CommonPopEntity>> data) {
                if(data.isSuccess()) {
                    ldType.postValue(data.getData());
                }
            }
        });
    }
    //我的公司
    public void getCompany(){
        NewAPIManager.getInstance().getTeamNewInterfaceAPI().myCompany().enqueue(new ICallBack<BaseEntity<List<MyCompanyEntity>>>() {
            @Override
            public void onSuccess(BaseEntity<List<MyCompanyEntity>> data) {
                if(data.isSuccess()){
                    ldCompany.postValue(data.getData());
                }
            }
        });
    }

    public void apply(ApplyCompanyEntity companyEntity){
        NewAPIManager.getInstance().getTeamNewInterfaceAPI().applyJoin(companyEntity).enqueue(new ICallBack<BaseEntity>() {
            @Override
            public void onSuccess(BaseEntity data) {
                if(data.isSuccess()){
                    ldResult.postValue(true);
                }
            }
        });

    }
}
